import '../constants/_index.dart';
import '_index.dart';

/// 实体生成器
class FactoryModel {
  static T getInstance<T>(json) {
    var model;
    var moduleName = T.toString();
    switch (moduleName) {
      case 'AuthorModel':
        model = AuthorModel.fromJson(json);
        break;
      case 'BaseConfig':
        model = BaseConfig.fromJson(json);
        break;
      case 'CacheConfModel':
        model = CacheConfModel.fromJson(json);
        break;
      case 'ChapterBarrageModel':
        model = ChapterBarrageModel.fromJson(json);
        break;
      case 'ChapterCatalogModel':
        model = ChapterCatalogModel.fromJson(json);
        break;
      case 'ChapterImageModel':
        model = ChapterImageModel.fromJson(json);
        break;
      case 'ChapterModel':
        model = ChapterModel.fromJson(json);
        break;
      case 'ChapterSlotModel':
        model = ChapterSlotModel.fromJson(json);
        break;
      case 'ComicModel':
        model = ComicModel.fromJson(json);
        break;
      case 'CommentModel':
        model = CommentModel.fromJson(json);
        break;
      case 'HomeModel':
        model = HomeModel.fromJson(json);
        break;
      case 'MobileBindModel':
        model = MobileBindModel.fromJson(json);
        break;
      case 'PrizeNoticeModel':
        model = PrizeNoticeModel.fromJson(json);
        break;
      case 'SimpleKeyModel':
        model = SimpleKeyModel.fromJson(json);
        break;
      case 'SmsCodeModel':
        model = SmsCodeModel.fromJson(json);
        break;
      case 'SortComicModel':
        model = SortComicModel.fromJson(json);
        break;
      case 'UserAccountModel':
        model = UserAccountModel.fromJson(json);
        break;
      case 'UserLimitItemModel':
        model = UserLimitItemModel.fromJson(json);
        break;
      case 'UserRecordModel':
        model = UserRecordModel.fromJson(json);
        break;
      case 'UserScoreItemModel':
        model = UserScoreItemModel.fromJson(json);
        break;
      case 'UserWithdrawItemModel':
        model = UserWithdrawItemModel.fromJson(json);
        break;
      case 'InviteInfoModel':
        model = InviteInfoModel.fromJson(json);
        break;
      case 'UserModel':
        model = UserModel.fromJson(json);
        break;
      case 'UserTokenModel':
        model = UserTokenModel.fromJson(json);
        break;
      default:
        return json;
    }
    return setCompatibleModel<T>(model);
  }

  /// 设置model状态
  static T setCompatibleModel<T>(model) {
    if (model != null) {
      model.modelState = ModelStateType.idle;
    }
    return model as T;
  }
}
